<template>
  <el-dialog
    :title="!this.dataForm.neId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm"  label-width="80px">
    <el-form-item label="" prop="neMessage">
      <el-input v-model="dataForm.neMessage" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="neCreatetime">
      <el-input v-model="dataForm.neCreatetime" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import api from "@/api/modules/cbbnotice";
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          neId: 0,
          neMessage: '',
          neCreatetime: ''
        },
        dataRule: {
          neMessage: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          neCreatetime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.neId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          api.info(this.dataForm.neId).then(({data}) => {
              if (data) {
                this.dataForm.neMessage = data.cbbNotice.neMessage
                this.dataForm.neCreatetime = data.cbbNotice.neCreatetime
              }
            })
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
    var parms= {
'neId': this.dataForm.neId || undefined,
'neMessage': this.dataForm.neMessage,
'neCreatetime': this.dataForm.neCreatetime        }
        api.updateAdd(parms,this.dataForm.neId).then((res) => {
              if (res.code==200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
